using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

namespace VotingSystem.ViewModels
{
    public class LoginViewModel
    {
        [Required(ErrorMessage = "请输入用户名")]
        [Display(Name = "用户名")]
        [RegularExpression(@"^[a-zA-Z0-9_]{3,20}$", ErrorMessage = "用户名必须是3-20位字母、数字或下划线")]
        public string UserName { get; set; } = string.Empty;

        [Required(ErrorMessage = "请输入密码")]
        [DataType(DataType.Password)]
        [Display(Name = "密码")]
        [RegularExpression(@"^[a-zA-Z0-9_]{6,20}$", ErrorMessage = "密码必须是6-20位字母、数字或下划线")]
        public string Password { get; set; } = string.Empty;

        [Display(Name = "记住我")]
        public bool RememberMe { get; set; }
    }

    public class RegisterViewModel
    {
        [Required(ErrorMessage = "请输入用户名")]
        [Display(Name = "用户名")]
        [RegularExpression(@"^[a-zA-Z0-9_]{3,20}$", ErrorMessage = "用户名必须是3-20位字母、数字或下划线")]
        public string UserName { get; set; } = string.Empty;

        [Required(ErrorMessage = "请输入邮箱")]
        [Display(Name = "邮箱")]
        [RegularExpression(@"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$", ErrorMessage = "请输入有效的邮箱地址")]
        public string Email { get; set; } = string.Empty;

        [Required(ErrorMessage = "请输入密码")]
        [Display(Name = "密码")]
        [DataType(DataType.Password)]
        [RegularExpression(@"^[a-zA-Z0-9_]{6,20}$", ErrorMessage = "密码必须是6-20位字母、数字或下划线")]
        public string Password { get; set; } = string.Empty;

        [DataType(DataType.Password)]
        [Display(Name = "确认密码")]
        [Compare("Password", ErrorMessage = "两次输入的密码不一致")]
        public string ConfirmPassword { get; set; } = string.Empty;
    }

    public class ChangePasswordViewModel
    {
        [Required(ErrorMessage = "请输入当前密码")]
        [DataType(DataType.Password)]
        [Display(Name = "当前密码")]
        public string CurrentPassword { get; set; } = string.Empty;

        [Required(ErrorMessage = "请输入新密码")]
        [StringLength(100, ErrorMessage = "密码长度必须在{2}到{1}个字符之间", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "新密码")]
        public string NewPassword { get; set; } = string.Empty;

        [DataType(DataType.Password)]
        [Display(Name = "确认新密码")]
        [Compare("NewPassword", ErrorMessage = "两次输入的密码不一致")]
        public string ConfirmPassword { get; set; } = string.Empty;
    }

    public class UserProfileViewModel
    {
        public string Id { get; set; } = string.Empty;
        public string UserName { get; set; } = string.Empty;
        public string Email { get; set; } = string.Empty;
        public DateTime RegisterTime { get; set; }
        public int CreatedVotesCount { get; set; }
        public int ParticipatedVotesCount { get; set; }
    }

    public class EditProfileViewModel
    {
        [Required(ErrorMessage = "请输入用户名")]
        [StringLength(50, ErrorMessage = "用户名长度必须在{2}到{1}个字符之间", MinimumLength = 3)]
        [Display(Name = "用户名")]
        public string UserName { get; set; } = string.Empty;

        [Required(ErrorMessage = "请输入邮箱")]
        [EmailAddress(ErrorMessage = "请输入有效的邮箱地址")]
        [Display(Name = "邮箱")]
        public string Email { get; set; } = string.Empty;
    }
} 